package transform;

import bean.SensorReading;
import org.apache.flink.api.java.tuple.Tuple;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Description: TODO QQ1667847363
 * @author: xiao kun tai
 * @date:2021/11/3 16:03
 */
public class Transform6_Partition {
    public static void main(String[] args) throws Exception{
        StreamExecutionEnvironment env =StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(8);


        String inputPath = "src/main/resources/sensor.txt";

        DataStream<String> inputStream = env.readTextFile(inputPath);


        DataStream<SensorReading> dataStream = inputStream.map(line->{
            String[] fields = line.split(",");
            return new SensorReading(fields[0],new Long(fields[1]),new Double(fields[2]));
        });


        inputStream.print("input");

        /**
         * 相同的id在一个线程
         */
        //dataStream.keyBy("id").print("keyby");

        /**
         *
         */
        inputStream.shuffle().print("shuffle");

        /**
         * 在同一个线程
         */
        inputStream.global().print("global");

        env.execute();
    }
}
